  <template>
  <div class="login-form">
    <el-form ref="formRef" :rules="formRules" :model="account">
      <el-form-item label="账号" prop="name">
        <el-input v-model="account.name" />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="account.password" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="width:100%;" @click="login">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
  <script setup>
import { reactive, ref } from 'vue'
import router from '@/router'
import userStore from '@/store/modules/login.js'

const account = reactive({
  name:'',
  password:''
})
const formRef = ref()

const store = userStore()
 const formRules = {
  name: [{ required: true, message: "用户名不能为空", trigger: "blur" }],
  password: [{ required: true, message: "密码不能为空", trigger: "blur" }],
 }

 const login = () => {
  formRef.value.validate((valid)=>{
    if(valid) {
      store.login(account)
    } 
  })
}
</script>
    
<style scoped lang="less">
.login-form {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.el-form {
  width: 300px;
  height: 150px;
  border: 1px solid #e5e5e5;
  padding: 20px;
  border-radius: 4px;
}
</style>
  